package com.mec.offload.controller;

import cn.hutool.json.JSONObject;
import com.mec.offload.model.MEC;
import com.mec.offload.service.MecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/offload/Mec")
@CrossOrigin
public class MecController{
    @Autowired
    MecService mecService;
    //@CrossOrigin(origins = "*")
    @RequestMapping("/getAllMec")
    @ResponseBody
    public List<MEC> getAllMec()
    {
        try {
           // List<MEC> data =mecService.getAllMec();
           return mecService.getAllMec();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    //@CrossOrigin(origins = "*")
    @RequestMapping("/getAllMec1")
    @ResponseBody
    public String getAllMec1( @RequestParam(required=false,defaultValue="1") int page,
                              @RequestParam(required=false,defaultValue="15") int limit)
    {
        List<MEC> data=mecService.queryAllDataFromTable(page,limit);
        int countx=  mecService.queryAllCount();
        try {
           // List<MEC> data =mecService.getAllMec();
            JSONObject jo = new JSONObject();
            jo.put("code",0);
            jo.put("msg","");
            jo.put("count",countx);
            jo.put("data", data);
            System.out.println(jo);
            return jo.toString();
            // return mecService.getAllMec();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
